﻿
using Zy.Shared.Rpc;
using Zy.Shared.Rpc.GrpcBase;
using Zy.Shared.Service.Authorizes;

namespace Zy.User.Services.GrpcService
{
    /// <summary>
    /// 用户GRPC服务
    /// </summary>
    /// <param name="logger"></param>
    /// <param name="repository"></param>
    [ZyAuthorize]
    public class UserGrpcService(ILogger<UserGrpcService> logger,
        IEfRepository<SysUser> repository) : UserGrpc.UserGrpcBase, IGrpcBaseServerService
    {
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task<UserInfoGrpcReply> GetUserInfo(GetUserGrpcRequest request, ServerCallContext context)
        {
            var user = await repository.FindAsync(request.Id);
            return new UserInfoGrpcReply
            {
                Id = user.Id,
                Name = user.Name,
                Sex = user.Sex,
                Address = user.Address,
                UserIdCard = user.UserIdCard,
                Photo = user.Photo,
                DataScope = (int)user.DataScope,
                Account = user.Account,
                Email = user.Email,
                Phone = user.Phone,
            };
        }
    }
}
